
package tiling;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;

/**
 *
 * @author ant
 * 
 * Represents the map of a loading area. It consists of TiledSubMaps. 
 */
public class AreaMap
{
    //TODO: consider replacing with Quadtree when ready
    private ArrayList<TiledSubMap> submaps;
    
    //in world coordinates
    public void render(Rectangle euclideanToRender)
    {
        for(TiledSubMap submap : submaps)
        {
            submap.renderSpace(euclideanToRender);
        }
    }
    
    //for now just load a default map
    public AreaMap() throws SlickException
    {
        submaps = new ArrayList<>();
                
        submaps.add(new TiledSubMap("assets/maps/level1.tmx", 0, 0));
    }
    
    public List<Rectangle> getWalls()
    {
        ArrayList<Rectangle> list = new ArrayList<>();
        
        for(TiledSubMap submap : submaps)
        {
            list.addAll(submap.walls);
        }
        
        return list;
    }
    
    public Vector2f getPlayerStart()
    {
        //assume there will be only one in any sub map
        
        for(TiledSubMap submap : submaps)
        {
            if(submap.enemy_start != null)
                return submap.player_start;
        }
        throw new NoSuchElementException();
    }
    
    public List<Vector2f> getEnemyStarts()
    {
        ArrayList<Vector2f> list = new ArrayList<>();
        
        for(TiledSubMap submap: submaps)
        {
            list.addAll(submap.enemy_start);
        }
        return list;
    }
}
